package cn.iocoder.yudao.module.wecom.controller.admin.momentlog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wecom.controller.admin.momentlog.vo.*;
import cn.iocoder.yudao.module.wecom.dal.dataobject.momentlog.MomentLogDO;
import cn.iocoder.yudao.module.wecom.service.momentlog.MomentLogService;

@Tag(name = "管理后台 - 朋友圈记录")
@RestController
@RequestMapping("/wecom/moment-log")
@Validated
public class MomentLogController {

    @Resource
    private MomentLogService momentLogService;

    @PostMapping("/create")
    @Operation(summary = "创建朋友圈记录")
    @PreAuthorize("@ss.hasPermission('wecom:moment-log:create')")
    public CommonResult<Long> createMomentLog(@Valid @RequestBody MomentLogSaveReqVO createReqVO) {
        return success(momentLogService.createMomentLog(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除朋友圈记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wecom:moment-log:delete')")
    public CommonResult<Boolean> deleteMomentLog(@RequestParam("id") Long id) {
        momentLogService.deleteMomentLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得朋友圈记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wecom:moment-log:query')")
    public CommonResult<MomentLogRespVO> getMomentLog(@RequestParam("id") Long id) {
        MomentLogDO momentLog = momentLogService.getMomentLog(id);
        return success(BeanUtils.toBean(momentLog, MomentLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得朋友圈记录分页")
    @PreAuthorize("@ss.hasPermission('wecom:moment-log:query')")
    public CommonResult<PageResult<MomentLogRespVO>> getMomentLogPage(@Valid MomentLogPageReqVO pageReqVO) {
        PageResult<MomentLogDO> pageResult = momentLogService.getMomentLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MomentLogRespVO.class));
    }


}